<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>用户编辑</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/libs/layui2.2.5/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="icon" href="href="${pageContext.request.contextPath}/static/libs/uiframe/frame/static/image/code.png">
    <form class="layui-form c3form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称：</label>
            <div class="layui-input-block">
                <input type="text" name="roleName" value="${role.roleName}"
                       lay-verify="rolename" autocomplete="off" placeholder="请输入角色名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色别名：</label>
            <div class="layui-input-block">
                <input type="text" name="aliasName" value="${role.aliasName}"
                       lay-verify="rolename" autocomplete="off" placeholder="请输入角色别名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色描述：</label>
            <div class="layui-input-block">
                <input type="text" name="description" value="${role.description}"
                       lay-verify="description" placeholder="请输入角色描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否锁定：</label>
            <div class="layui-input-block">
                <c:choose>
                    <c:when test="${role.available == 'true'}">
                        <input type="radio" name="available" value="true" title="是" >
                        <input type="radio" name="available" value="false" title="否" checked="checked" >
                    </c:when>
                    <c:when test="${role.available == 'false'}">
                        <input type="radio" name="available" value="true" title="是" checked="checked" >
                        <input type="radio" name="available" value="false" title="否" >
                    </c:when>
                    <c:otherwise>
                        <input type="radio" name="available" value="true" title="是" >
                        <input type="radio" name="available" value="false" title="否" checked="checked">
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序编号：</label>
            <div class="layui-input-block">
                <input type="text" name="sortedNum" value="${role.sortedNum}" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="roleadd">提 交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
            </div>
        </div>
    </form>

    <script type="text/javascript" src="${pageContext.request.contextPath}/static/libs/layui2.2.5/layui.js"></script>
    <script>
        var roleId = '${role.roleId}';

        layui.use(['form','layer'],function(){
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;
            <%--$("input[name='username']").val('${user.username}');--%>

            //自定义验证规则
            form.verify({
                rolename: function(value){
                    if(value.length < 2){
                        return '角色至少得2个字符啊';
                    }
                },
                description: function(value){
                    if(value.length < 2){
                        return '描述至少得2个字符啊';
                    }
                }
            });

            //监听提交
            form.on('submit(roleadd)', function(data){
                var formData = data.field,url;
                if(roleId == ""){
                    url = '${pageContext.request.contextPath}/sys/user/rolecreate';
                }else{
                    url = '${pageContext.request.contextPath}/sys/user/roleupdate';
                }
                $.ajax({
                    type:'post',
                    dataType:'json',
                    url:url,
                    data:{
                        roleId:roleId,
                        roleName:formData['roleName'],
                        aliasName:formData['aliasName'],
                        description:formData['description'],
                        available:formData['available'],
                        sortedNum:formData['sortedNum']
                    },
                    success:function (data) {
                        layer.msg(data.status);
                        window.parent.layIndex = null;
                        window.parent.closeAllLayer();
                    },
                    error:function (error) {
                        console.log(error);
                    }
                });
                return false;
            });
        })
    </script>
</head>
<body>

</body>
</html>
